import operate from '@dfeidao/atom-nodejs/db/operate';
import doc_code from '@dfeidao/atom-nodejs/msg/doc-code';
import { IncomingHttpHeaders } from 'http';
import { systemid } from '../../atom/config';
interface Message {
	filter: {
		productid: string,
		record_no: string,
		project_id: string,
		project_name: string,
		inventory_time: number,
		inventory_people: string,
		inventory_people_no: string,
		lnventory_name: string,
		project_asset_no: string,
		assetsname: string,
		brand_no: string
	};
}
/* 表名	asset_inventory
标题	资产盘点
字段名称	字段标题	字段类型	字段长度	是否为空	是否主键
project_name	项目名称	string	500	√	ⅹ
inventory_people	盘点人	string	50	√	ⅹ
inventory_time	盘点时间	timestamp	50	√	ⅹ
_id	id	string	50	ⅹ	√
productid	产品id	string	50	√	ⅹ
project_id	项目编号	string	50	√	ⅹ
customer_reviews	客户签名	blob	50	√	ⅹ
record_no	记录编号	string	50	√	ⅹ
lnventory_name	盘点名称	string	100	√	ⅹ
inventory_people_no	盘点人编号	string	50	√	ⅹ */

export default async function atom(message: Message, action_id: string, session_id: string, headers: IncomingHttpHeaders) {
	const r = await doc_code(action_id, session_id, systemid, 'BM0019560', '', 1);
	const s = await doc_code(action_id, session_id, systemid, 'BM0019562', '', 1);
	const { exec, insert } = operate(action_id, session_id, systemid);
	// 插入数据
	insert('asset_inventory', {
		record_no: r.result, productid: message.filter.productid,
		project_id: message.filter.project_id, project_name: message.filter.project_name,
		inventory_time: message.filter.inventory_time, inventory_people: message.filter.inventory_people,
		inventory_people_no: message.filter.inventory_people_no, lnventory_name: message.filter.lnventory_name
	});

	insert('lnventory_details', {
		lnventory_details_no: s.result, productid: message.filter.productid,
		project_asset_no: message.filter.project_asset_no, assetsname: message.filter.assetsname,
		brand_no: message.filter.brand_no, record_no: r.result
	});
	const res = await exec();
	return res;



}
